using UnityEngine;

namespace RGuang.PlathformCtrl
{

    public class BlackBall : MonoBehaviour
    {
        [SerializeField] VoidEventChannel gateTriggerEventChannel;
        [SerializeField] float lifeTime = 7f;
        private void OnEnable()
        {
            gateTriggerEventChannel.AddListener(OnGateTriggered);
        }
        private void OnDisable()
        {
            
            gateTriggerEventChannel.RemoveListener(OnGateTriggered);
        }
        private void OnCollisionEnter(Collision collision)
        {
            if (collision.gameObject.TryGetComponent(out PlayerController player))
            {
                player.OnDefeated();
            }
        }

        void OnGateTriggered()
        {
            Destroy(gameObject, lifeTime);
        }

    }
}

